package com.itheima.service.impl;


import com.itheima.dto.OrdersStatisticsDto;
import com.itheima.feign.OrderClient;
import com.itheima.feign.UserClient;
import com.itheima.service.ReportService;
import com.itheima.vo.TurnoverReportVO;
import com.itheima.vo.UserReportVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class ReportServiceImpl implements ReportService {


//    @Autowired
//    private OrderMapper orderMapper;

    @Autowired
    private OrderClient orderClient;
//    @Autowired
//    private UserMapper userMapper;
    @Autowired
    private UserClient userClient;
    /**
     * 营业额统计接口
     * @param statisticsDto
     * @return
     */
    @Override
    public TurnoverReportVO turnoverStatistics(OrdersStatisticsDto statisticsDto) {

//        TurnoverReportVO vo=orderMapper.turnoverStatistics(statisticsDto);
        TurnoverReportVO vo = orderClient.turnoverStatistics(statisticsDto);
        return vo;
    }
    /**
     * 用户统计接口
     * @param statisticsDto
     * @return
     */
    @Override
    public UserReportVO userStatistics(OrdersStatisticsDto statisticsDto) {

//        UserReportVO vo=userMapper.userStatistics(statisticsDto);
        UserReportVO vo = userClient.userStatistics(statisticsDto);
        log.info("为{}",vo);
        return vo;
    }
//    /**
//     * 导出Excel报表接口
//     * @param response
//     */
//    @Override
//    @SneakyThrows
//    public void exportBusinessData(HttpServletResponse response) {
//        LocalDate begin = LocalDate.now().minusDays(30);
//        LocalDate end = LocalDate.now().minusDays(1);
//
////        BusinessDataVO businessDataVO = orderMapper.getBusinessData(LocalDateTime.of(begin,LocalTime.MIN),LocalDateTime.of(end, LocalTime.MAX));
//        BusinessDataVO businessDataVO = orderClient.getBusinessData(LocalDateTime.of(begin, LocalTime.MIN), LocalDateTime.of(end, LocalTime.MAX));
//
//        log.info("{}为",businessDataVO);
//
////        Integer newUsers=userMapper.getNewUser(LocalDateTime.of(begin,LocalTime.MIN),LocalDateTime.of(end, LocalTime.MAX));
//        Integer newUsers = userClient.getNewUser(LocalDateTime.of(begin, LocalTime.MIN), LocalDateTime.of(end, LocalTime.MAX));
//        businessDataVO.setNewUsers(newUsers);
//        log.info("{}为",businessDataVO);
//        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("temaplate/运营数据报表模板.xlsx");
//        XSSFWorkbook excel = new XSSFWorkbook(inputStream);
//        XSSFSheet sheet = excel.getSheet("Sheet1");
//        sheet.getRow(1).getCell(1).setCellValue(begin+"至"+end);
//        XSSFRow row = sheet.getRow(3);
//        row.getCell(2).setCellValue(businessDataVO.getTurnover());
//        row.getCell(4).setCellValue(businessDataVO.getOrderCompletionRate());
//        row.getCell(6).setCellValue(businessDataVO.getNewUsers());
//        row = sheet.getRow(4);
//        row.getCell(2).setCellValue(businessDataVO.getValidOrderCount());
//        row.getCell(4).setCellValue(businessDataVO.getUnitPrice());
//
//
//
////        for (int i = 0; i < 30; i++) {
////            LocalDate date = begin.plusDays(i);
////
////            businessDataVO = orderMapper.getBusinessData(LocalDateTime.of(date, LocalTime.MIN), LocalDateTime.of(date, LocalTime.MAX));
////
////            newUsers=userMapper.getNewUser(LocalDateTime.of(date,LocalTime.MIN),LocalDateTime.of(date, LocalTime.MAX));
////
////
////            row= sheet.getRow(7+i);
////            row.getCell(1).setCellValue(date.toString());
////            row.getCell(2).setCellValue(businessDataVO.getTurnover());
////            row.getCell(3).setCellValue(businessDataVO.getValidOrderCount());
////            row.getCell(4).setCellValue(businessDataVO.getOrderCompletionRate());
////            row.getCell(5).setCellValue(businessDataVO.getUnitPrice());
////            row.getCell(6).setCellValue(newUsers);
////
////        }
//
//
////           List<BusinessDataVO> vo = orderMapper.getData(begin,end);
//        List<BusinessDataVO> vo = orderClient.getData(begin, end);
//        log.info("{}为哈哈动画",vo);
//
//
//        for (int i = 0; i < vo.size(); i++) {
//            BusinessDataVO bu = vo.get(i);
//            row= sheet.getRow(7+i);
//
//            row.getCell(1).setCellValue(begin.toString());
//            row.getCell(2).setCellValue(bu.getTurnover());
//            row.getCell(3).setCellValue(bu.getValidOrderCount());
//            row.getCell(4).setCellValue(bu.getOrderCompletionRate());
//            row.getCell(5).setCellValue(bu.getUnitPrice());
//            row.getCell(6).setCellValue(bu.getNewUsers());
//            begin=begin.plusDays(1);
//        }
//
//
//
//        ServletOutputStream outputStream = response.getOutputStream();
//        excel.write(outputStream);
//        outputStream.flush();
//        outputStream.close();
//        excel.close();
//
//    }
}
